package com.jorenwu.asymmetric;

import java.io.ObjectOutputStream;
import java.io.Writer;
import java.math.BigInteger;

public class JorenEncoder
{
	public BigInteger stringToInteger(String str)
	{
		return new BigInteger(str);
	}

	public String inttostring(int ch)
	{
		return Integer.toString(ch);
	}

	public BigInteger inputBlockEncrypto(int ch)
	{
		return stringToInteger(inttostring(ch));
	}
	
	public void outputBlockEncrypto(ObjectOutputStream out, BigInteger bi)
	{
		byte[] src = bi.toByteArray();
		Media je=new Media(src);
		try
		{
			out.writeObject(je);
			out.flush();
		} catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
	
	public BigInteger inputBlockDecrypto(Media bt)
	{
		return new BigInteger(bt.bt);
	}

	public void outputBlockDecrypto(Writer writer, BigInteger bi)
	{
		try
		{
			writer.write(bi.intValue());
		} catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
